package com.coder.chen.slidingmenu;

import com.coder.chen.slidingmenu.view.LeftFragment;
import com.coder.chen.slidingmenu.view.RightFragment;
import com.coder.chen.slidingmenu.view.SampleListFragment;
import com.coder.chen.slidingmenu.view.SlidingMenu;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.util.DisplayMetrics;

public class MainActivity extends FragmentActivity {

	private SlidingMenu mSlidingMenu;

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.activity_main);

		init();
	}

	private void init() {
		// 根据屏幕的大小，按比例计算图片的高度
		DisplayMetrics dm = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(dm);

		mSlidingMenu = (SlidingMenu) findViewById(R.id.slidingMenu);
		mSlidingMenu.setAlignScreenWidth((dm.widthPixels / 5) * 4);
		
		mSlidingMenu.setLeftView(getLayoutInflater().inflate(R.layout.left_frame, null));
		mSlidingMenu.setRightView(getLayoutInflater().inflate(R.layout.right_frame, null));
		mSlidingMenu.setCenterView(getLayoutInflater().inflate(R.layout.center_frame, null));
		
		FragmentTransaction transaction = this.getSupportFragmentManager().beginTransaction();
		LeftFragment leftFragment = new LeftFragment();
		transaction.replace(R.id.left_frame, leftFragment);
		
		RightFragment rightFragment = new RightFragment();
		transaction.replace(R.id.right_frame, rightFragment);
		
		SampleListFragment centerFragment = new SampleListFragment();
		transaction.replace(R.id.center_frame, centerFragment);
		
		transaction.commit();
	}

}
